package cn.jiyun;

import com.mongodb.BasicDBObject;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

//Mongo入门Demo
public class MongoUpdate {
    //查询所有
    public static void main(String[] args) {
        //创建连接
        MongoClient client=new MongoClient("127.0.0.1");
        //打开数据库
        MongoDatabase spitdb = client.getDatabase("spitdb");
        //获取集合
        MongoCollection<Document> spit = spitdb.getCollection("spit");

        BasicDBObject bson=new BasicDBObject("userid","1002");

        BasicDBObject bson1=new BasicDBObject("$set",new BasicDBObject("name","小周老六"));
        //插入数据
        spit.updateOne(bson,bson1);
        //关闭连接
        client.close();
    }

}
